package org.wutopia.leo.resource;



import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wutopia.leo.applicaiton.payment.PaymentApplicationService;
import org.wutopia.leo.applicaiton.payment.dto.Settlement;
import org.wutopia.leo.domain.payment.Payment;
import org.wutopia.leo.domain.payment.validation.SufficientStock;


/**
 * 结算清单相关的资源
 *
 **/
@RequestMapping("/api/v1/settlements")
@RestController
public class SettlementResource {

    @Autowired
    private PaymentApplicationService service;

    /**
     * 提交一张交易结算单，根据结算单中的物品，生成支付单
     */
    @PostMapping("/")
    public Payment executeSettlement(@RequestBody @Valid @SufficientStock Settlement settlement) {
        return service.executeBySettlement(settlement);
    }

}
